package com.usian.wemedia.controller;

import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.common.enums.AppHttpCodeEnum;
import com.usian.model.media.pojos.WmUser;
import com.usian.wemedia.ApWemediaControllerApi;
import com.usian.wemedia.service.ApWeMedicService;
import com.usian.wemedia.service.WmMaterialService;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/user")
@MapperScan("com.usian.wemedia.mapper")
public class ApWeMediaController implements ApWemediaControllerApi {

    @Autowired
    ApWeMedicService service;

    @Autowired
    WmMaterialService wmMaterialService;

    /**
     * 保存自媒体用户
     * @param wmUser
     * @return
     */
    @Override
    @PostMapping("/save")
    public ResponseResult save(@RequestBody WmUser wmUser) {
        if (wmUser == null){
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_REQUIRE);
        }
        boolean save = service.save(wmUser);
        return save?ResponseResult.okResult(wmUser.getId()):ResponseResult.errorResult(AppHttpCodeEnum.SAVE_FAILED);
    }

    @Override
    @GetMapping("/findByName/{name}")
    public WmUser findByName(@PathVariable("name") String name) {
        return null;
    }

    @Override
    @PostMapping("/update")
    public ResponseResult update(@RequestBody WmUser wmUser) {
        boolean b = service.updateById(wmUser);

        return b?ResponseResult.okResult(AppHttpCodeEnum.SUCCESS):ResponseResult.errorResult(AppHttpCodeEnum.SAVE_FAILED);
    }

    @Override
    @GetMapping("/one/{id}")
    public WmUser findWmUserById(@PathVariable("id") Integer id) {
        if (id==null)return null;
        return service.getById(id);
    }


}
